package scuba.DiveBuddy.Class;

import android.content.Context;
import android.graphics.Canvas;
import android.util.Log;
import org.achartengine.ChartFactory;
import org.achartengine.GraphicalView;
import org.achartengine.model.XYMultipleSeriesDataset;
import org.achartengine.model.XYSeries;
import org.achartengine.renderer.XYMultipleSeriesRenderer;
import org.achartengine.renderer.XYSeriesRenderer;
import org.joda.time.Period;
import scuba.DiveBuddy.Enums.DistanceEnum;
import scuba.DiveBuddy.Enums.GraphViewEnum;

import java.util.ArrayList;

/**
 * @author Alex Anderson
 * @version 1.0
 * @since {12/03/14}
 */
public class GraphViews {

    public static GraphViewEnum Graph;

    public static GraphicalView getTotalDiveTimeData(Context ctx) {

        Log.v("INTERFACE", "getTotalDiveTimeData()");
        int x = 0;
        int cumulative = 0;
        XYSeries series = new XYSeries("Cumulative Dive Time");
        for(LogEntry log : LogEntries.getInstance().getEntries()) {

            //assume they are already ordered
            //foreach log, create a point with new cumulativeTime
            //e.g. (1,35) (2, 60) etc.
            cumulative += log.getDiveDuration();
            series.add(x++, cumulative);
            Log.v("INTERFACE", "TotalDive Data x=" + x + " t=" + cumulative);
        }

        XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
        dataset.addSeries(series);

        XYMultipleSeriesRenderer render = new XYMultipleSeriesRenderer();
        render.addSeriesRenderer(new XYSeriesRenderer());

        return ChartFactory.getLineChartView(ctx, dataset, render);
    }

    /*public static GraphView getDiveDurationData(Context ctx) {
        ArrayList<GraphView.GraphViewData> data = new ArrayList<GraphView.GraphViewData>();
        Log.v("INTERFACE", "getDiveDurationData()");
        int x = 0;

        for(LogEntry log : LogEntries.getInstance().getEntries()) {
            //assume they are already ordered
            data.add(new GraphView.GraphViewData(x, log.getDiveDuration()));

            Log.v("INTERFACE", "TotalDive Data x=" + x + " t=" + log.getDiveDuration());
            x++;
        }

        GraphViewSeries series = new GraphViewSeries(data.toArray(new GraphView.GraphViewData[data.size()]));
        GraphView v = new BarGraphView(ctx, "Dive Durations");
        return v;
    }

    public static GraphView getAirConsumptionRateData(Context ctx) {
        ArrayList<GraphView.GraphViewData> data = new ArrayList<GraphView.GraphViewData>();
        Log.v("INTERFACE", "getAirConsumptionRateData()");

        int x = 0;
        for(LogEntry log : LogEntries.getInstance().getEntries()) {
            //assume they are already ordered
            data.add(new GraphView.GraphViewData(x, log.getStartAir() - log.getEndAir()));
            Log.v("INTERFACE", "TotalDive Data x=" + x + " t=" + (log.getStartAir() - log.getEndAir()));
            x++;
        }

        GraphViewSeries series = new GraphViewSeries(data.toArray(new GraphView.GraphViewData[data.size()]));
        GraphView v = new LineGraphView(ctx, "Air Consumption");
        return v;
    }*/
}
